/*
 * mp3Sink.h
 *
 *  Created on: 20 janv. 2010
 *      Author: mdulongpont
 */

#ifndef MRSINK_H_
#define MRSINK_H_

#ifndef _MEDIA_SINK_HH
#include "MediaSink.hh"
#endif

#include <fstream>

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>

#include <queue>
using namespace std;

class MRSink : public MediaSink{
public:
	static MRSink* createNew(UsageEnvironment& env, unsigned bufferSize = 20000);
	void addData(void* data, unsigned dataSize,struct timeval presentationTime);
	AVPacket * getNext();
	//test de l'�criture
	void writePacketsInFile();
	unsigned int getQueueSize();
	pthread_mutex_t mutexForQueue;


protected:
	MRSink(UsageEnvironment& env, unsigned bufferSize);
	virtual ~MRSink();

protected:
	static void afterGettingFrame(void* clientData, unsigned frameSize,unsigned numTruncatedBytes, struct timeval presentationTime,unsigned durationInMicroseconds);
	virtual void afterGettingFrame1(unsigned frameSize,struct timeval presentationTime);
	unsigned char* fBuffer;
	unsigned fBufferSize;
	queue <AVPacket*> avPackets;
	int index;
	//char* fPerFrameFileNamePrefix; // used if "oneFilePerFrame" is True
	//char* fPerFrameFileNameBuffer; // used if "oneFilePerFrame" is True

private: // redefined virtual functions:
	virtual Boolean continuePlaying();
};

#endif /* MRSINK_H_ */
